/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modelo;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;

/**
 *
 * @author Guille
 */
public class SOCKS4Proxy {

    private String host;
    private int port;
    private int CONNECT = 1;
    private int BIND = 2;
    private byte[] user = null;

    public SOCKS4Proxy(String host, int port)
    {

    }

    public String doRequest() throws Exception
    {
        SocketConnection conn = (SocketConnection)Connector.open(host+":"+port);
        connect(conn);

    return "";
    }

    public void connect(SocketConnection conn) throws Exception
    {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream(100);
        byte[] addr = {0,0,0,42};

        byte[] tmp = "".getBytes();
        user = new byte[tmp.length+1];
        System.arraycopy(tmp, 0, user, 0, tmp.length);
        user["".length()] = 0;

        buffer.reset();
        buffer.write(4);                                // version
        buffer.write(CONNECT);                          // command
        buffer.write((port >> 8) & 0xff);               // port
        buffer.write(port & 0xff);
        buffer.write(addr);                             // address
        buffer.write(user);
    }


}
